package com.chagee.channel.server.event.facade;

import com.chagee.base.utils.SoaResponse;
import com.chagee.base.utils.SoaUtil;
import com.chagee.channel.api.bo.ocr.BaseFileUrlReq;
import com.chagee.channel.api.bo.ocr.BusinessLicenseOcrDTO;
import com.chagee.channel.api.bo.ocr.IdCardBackDTO;
import com.chagee.channel.api.bo.ocr.IdCardFrontDTO;
import com.chagee.channel.api.service.IOCRServiceApi;
import com.chagee.channel.common.exception.BizErrorCode;
import com.chagee.channel.common.exception.BizException;
import com.chagee.channel.server.event.service.OcrService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author: chang.jiawei
 * @date: 2024/03/06
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class OcrServiceRpcImpl implements IOCRServiceApi {

    private final OcrService ocrService;

    @Override
    public SoaResponse<BusinessLicenseOcrDTO, Void> ocrBusinessLicense(BaseFileUrlReq param) {
        try {
            BusinessLicenseOcrDTO result = ocrService.ocrBusinessLicense(param.getFileUrl());
            return SoaUtil.ok(result);
        } catch (Exception error) {
            throw new BizException(BizErrorCode.OCR_FAIL);
        }
    }

    @Override
    public SoaResponse<IdCardFrontDTO, Void> ocrIdCardFront(BaseFileUrlReq param) {
        try {
            IdCardFrontDTO idCardFrontDTO = ocrService.ocrIdCardFront(param.getFileUrl());
            return SoaUtil.ok(idCardFrontDTO);
        } catch (Exception error) {
            throw new BizException(BizErrorCode.OCR_FAIL);
        }
    }

    @Override
    public SoaResponse<IdCardBackDTO, Void> ocrIdCardBack(BaseFileUrlReq param) {
        try {
            IdCardBackDTO idCardBackDTO = ocrService.ocrIdCardBack(param.getFileUrl());
            return SoaUtil.ok(idCardBackDTO);
        } catch (Exception error) {
            throw new BizException(BizErrorCode.OCR_FAIL);
        }
    }
}
